

DEFINE BUFFER pt FOR pt_mstr.

DEFINE VARIABLE amt LIKE sct_cst_tot.
                                      
OUTPUT TO c:\ln530.txt .

FOR EACH pt_mstr NO-LOCK WHERE pt_mstr.pt_prod_line = "164",
    EACH ps_mstr NO-LOCK WHERE ps_par = pt_mstr.pt_part
    BREAK BY pt_part WITH FRAME a STREAM-IO WIDTH 132 DOWN :
    
    FIND FIRST IN_mstr NO-LOCK WHERE IN_part = ps_comp AND IN_site = "530" NO-ERROR.
    IF AVAILABLE IN_mstr THEN
        FIND FIRST sct_det NO-LOCK WHERE sct_sim = "standard" AND sct_part = ps_comp AND sct_site = IN_gl_cost_site NO-ERROR.
    ELSE 
        FIND FIRST sct_det NO-LOCK WHERE sct_sim = "standard" AND sct_part = ps_comp AND sct_site = "500" NO-ERROR.
    
    FIND FIRST pt NO-LOCK WHERE pt.pt_part = ps_comp NO-ERROR.

    IF AVAILABLE sct_det THEN
        DISP ps_par pt_mstr.pt_status ps_comp pt.pt_status ps_qty_per sct_cst_tot sct_cst_tot * ps_qty_per @ amt
        IN_site WHEN AVAILABLE in_mstr
        "500" WHEN NOT AVAILABLE in_mstr @ IN_site 
        IN_gl_cost_site  WHEN AVAILABLE in_mstr
        "500" WHEN NOT AVAILABLE in_mstr @ IN_gl_cost_site 
        WITH STREAM-IO.
    ELSE
        DISP  ps_par pt_mstr.pt_status ps_comp pt.pt_status ps_qty_per 0 @ sct_cst_tot  0 @ amt
        IN_site WHEN AVAILABLE in_mstr
        "500" WHEN NOT AVAILABLE in_mstr @ IN_site 
        IN_gl_cost_site  WHEN AVAILABLE in_mstr
        "500" WHEN NOT AVAILABLE in_mstr @ IN_gl_cost_site 
        WITH STREAM-IO.

    IF LAST-OF(pt_mstr.pt_part) THEN
        DOWN 2 WITH FRAME a .

END.
